package cn.bugstack.deepseek.session;

import cn.bugstack.deepseek.executor.Executor;
import cn.bugstack.deepseek.executor.model.deepseek.DeepSeekModelExecutor;
import cn.bugstack.deepseek.executor.model.deepseek.config.DeepSeekConfig;
import cn.bugstack.deepseek.executor.parameter.CompletionRequest;
import cn.bugstack.openai.executor.model.chatglm.config.ChatGLMConfig;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.sse.EventSource;
import okhttp3.sse.EventSources;

import java.util.HashMap;

/**
 * 配置中心
 */

@Slf4j
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Configuration {

    @Getter
    @Setter
    private String apiHost = "https://api.deepseek.com/";

    @Getter
    @Setter
    private String apiSecretKey;

    /**
     * DeepSeek Config
     */
    private DeepSeekConfig deepSeekConfig;
    /**
     * 智谱Ai ChatGLM Config
     */
    private ChatGLMConfig chatGLMConfig;

    /**
     * OkHttpClient
     */
    private OkHttpClient okHttpClient;

    private HashMap<String, cn.bugstack.deepseek.executor.Executor> executorGroup;

    public EventSource.Factory createRequestFactory() {
        return EventSources.createFactory(okHttpClient);
    }


    // OkHttp 配置信息
    private HttpLoggingInterceptor.Level level = HttpLoggingInterceptor.Level.HEADERS;
    private long connectTimeout = 4500;
    private long writeTimeout = 4500;
    private long readTimeout = 4500;

    // http keywords
    public static final String SSE_CONTENT_TYPE = "text/event-stream";
    public static final String DEFAULT_USER_AGENT = "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)";
    public static final String APPLICATION_JSON = "application/json";
    public static final String JSON_CONTENT_TYPE = APPLICATION_JSON + "; charset=utf-8";

    public HashMap<String, cn.bugstack.deepseek.executor.Executor> newExecutorGroup(){
        this.executorGroup = new HashMap<>();
        //DeepSeek类型执行器填充
        Executor DeepSeekModelExecutor = new DeepSeekModelExecutor(this);
        executorGroup.put(cn.bugstack.deepseek.executor.parameter.CompletionRequest.Model.DEEPSEEK_V3.getCode(), DeepSeekModelExecutor);
        executorGroup.put(CompletionRequest.Model.DEEPSEEK_R1.getCode(), DeepSeekModelExecutor);
        //ChatGLM类型执行器填充
        // TODO : 智谱大模型对接

        return this.executorGroup;
    }
}
